#include<iostream>
#include<string>

#include"nfa.h"
#include"regex.h"

using std::cin;
using std::cout;
using std::endl;
using std::string;

int main() {
	RegExp * r;// = new ConcatRegExp(new KleeneRegExp(new LiteralRegExp("ab")), new KleeneRegExp(new LiteralRegExp("b")));
	/*cout << "aaab" << r -> match("aaab") << endl;
	cout << "aaabb" << r -> match("aaabb") << endl;
	cout << "b" << r -> match("b") << endl;
	cout << "aaa" << r -> match("aaa") << endl;
	cout << r -> toString() << endl;*/
	NFA n;// = r -> toNFA();
	//cout << n;
	//delete r;
	cin >> n;
	//cout << n;
	r = n . toRegExp();
	cout << r -> toString() << endl;
	delete r;
	return 0;
}
